package cn.loan.config.condition;

import cn.loan.config.key.EnvironmentalScience;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 17:40 2019/5/1
 */
public class RunConditions extends EnvironmentalScience implements Condition {


    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        final Environment environment = context.getEnvironment();
        final Map<String, String> env = System.getenv();
        final String user_name = env.get("USERNAME");
        final String computer_name = env.get("COMPUTERNAME");
        final String system_version = environment.getProperty("os.name");
        final String os_type = env.get("OS");
        if ("Linux".equals(system_version)) {
            return true;
        }
        if (user_name.equals(ENV_USER_NAME) && computer_name.equals(ENV_COMPUTER_NAME)
                && system_version.equals(ENV_SYSTEM_VERSION) && os_type.equals(ENV_OS_TYPE)) {
            return true;
        } else {
            return false;
        }
    }


}
